//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbKhoaHoc_GiangVien
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbKhoaHoc_GiangVien_SelectAll", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbKhoaHoc_GiangVien_SelectTop", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbKhoaHoc_GiangVien OTbKhoaHoc_GiangVien)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaKhoaHoc", OTbKhoaHoc_GiangVien.MaKhoaHoc);
            pr[1] = new SqlParameter(@"MaGV", OTbKhoaHoc_GiangVien.MaGV);
            pr[2] = new SqlParameter(@"GhiChu", OTbKhoaHoc_GiangVien.GhiChu);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbKhoaHoc_GiangVien_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbKhoaHoc_GiangVien OTbKhoaHoc_GiangVien)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaKhoaHoc", OTbKhoaHoc_GiangVien.MaKhoaHoc);
            pr[1] = new SqlParameter(@"MaGV", OTbKhoaHoc_GiangVien.MaGV);
            pr[2] = new SqlParameter(@"GhiChu", OTbKhoaHoc_GiangVien.GhiChu);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbKhoaHoc_GiangVien_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaKhoaHoc,int MaGV)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaKhoaHoc",MaKhoaHoc);
            pr[1] = new SqlParameter(@"MaGV",MaGV);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbKhoaHoc_GiangVien_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbKhoaHoc_GiangVien SelectByID(int MaKhoaHoc,int MaGV)
        {
            ETbKhoaHoc_GiangVien OTbKhoaHoc_GiangVien = new ETbKhoaHoc_GiangVien();
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaKhoaHoc",MaKhoaHoc);
            pr[1] = new SqlParameter(@"MaGV",MaGV);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbKhoaHoc_GiangVien_SelectByID", pr);
            if (idr.Read())
              OTbKhoaHoc_GiangVien = GetOneTbKhoaHoc_GiangVien(idr);
            idr.Close();
            idr.Dispose();
            return OTbKhoaHoc_GiangVien;
        }
//-----------------------------------------------------------//
        private static ETbKhoaHoc_GiangVien GetOneTbKhoaHoc_GiangVien(IDataReader idr)
       {
            ETbKhoaHoc_GiangVien OTbKhoaHoc_GiangVien = new ETbKhoaHoc_GiangVien();
                if (idr["MaKhoaHoc"] != DBNull.Value)
                    OTbKhoaHoc_GiangVien.MaKhoaHoc = (int)idr["MaKhoaHoc"];
                if (idr["MaGV"] != DBNull.Value)
                    OTbKhoaHoc_GiangVien.MaGV = (int)idr["MaGV"];
                if (idr["GhiChu"] != DBNull.Value)
                    OTbKhoaHoc_GiangVien.GhiChu = (string)idr["GhiChu"];
            return OTbKhoaHoc_GiangVien;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaKhoaHoc,int MaGV)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaKhoaHoc",MaKhoaHoc);
            pr[1] = new SqlParameter(@"MaGV",MaGV);
            pr[2] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[2].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbKhoaHoc_GiangVien_TestByID", pr);
            return Convert.ToBoolean(pr[2].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbKhoaHoc_GiangVien> ListAll()
        {
            List<ETbKhoaHoc_GiangVien> list = new List<ETbKhoaHoc_GiangVien>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbKhoaHoc_GiangVien_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbKhoaHoc_GiangVien(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbKhoaHoc_GiangVien> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbKhoaHoc_GiangVien> list = new List<ETbKhoaHoc_GiangVien>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbKhoaHoc_GiangVien_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbKhoaHoc_GiangVien(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}